$(function() {
  $(':button#partscan').bind('click', function() {
    $.getJSON('/_scankeyparts', {
      ssn: $('input[name="ssn"]').val(),
      part1: $('input[name="part1"]').val(),
      part2: $('input[name="part2"]').val(),
      part3: $('input[name="part3"]').val(),
      part4: $('input[name="part4"]').val(),
      part5: $('input[name="part5"]').val(),
      part6: $('input[name="part6"]').val(),
      part7: $('input[name="part7"]').val(),
      part8: $('input[name="part8"]').val(),
      part9: $('input[name="part9"]').val(),
      part10: $('input[name="part10"]').val(),          
      wono: $("#wono").text(),
      station: $("#station").text(),
      line: $("#line").text(),
      item: $("#item").text(),
      failcode: $('select[name="failcode"]').val(),
      date: new Date().getTime()+Math.random()
    }, function(data) {
      var beginstr = data.result.substring(0, 4);
      if(data.result == 'RELOGIN')
      {
        location.href = "/login";
      }
      else
      {
        if(beginstr == 'SSN:')
        {
          $("#result").text("");
          $("#result2").text(data.result);
        }
        else
        {
          $("#result").text(data.result);
          $("#result2").text("");
        }
        if($("#result").text() == "")
        {
          var d = new Date().format("yyyy-MM-dd hh:mm:ss");
          var s_ssn = ssn.value;
          var s_sta = $("#station").text();
          $("#flowdetail").val(d + "   " + s_ssn + " finished in station: " + s_sta + "\r" + $("#flowdetail").text());  
        }
        var pqty = data.passedqty;
        if (pqty != "")
        {
          document.getElementById("passqty").innerText = String(pqty);
        }
        ssn.value = "";
      }
    });
    return false;
  });
})

function txtKeyDown()
{
  if(event.keyCode == 13)
  {
    partscan.click();
    ssn.focus();
    if(document.getElementById("part1"))
    {
      part1.value = "";
    }
    if(document.getElementById("part2"))
    {
      part2.value = "";
    }
    if(document.getElementById("part3"))
    {
      part3.value = "";
    }
    if(document.getElementById("part4"))
    {
      part4.value = "";
    }
    if(document.getElementById("part5"))
    {
      part5.value = "";
    }
    if(document.getElementById("part6"))
    {
      part6.value = "";
    }
    if(document.getElementById("part7"))
    {
      part7.value = "";
    }
    if(document.getElementById("part8"))
    {
      part8.value = "";
    }
    if(document.getElementById("part9"))
    {
      part9.value = "";
    }
    if(document.getElementById("part10"))
    {
      part10.value = "";
    }
  }
}